PF Optimization: HRP vs Markowitz and Equal-Weighted Positions

Imports & Settings

This notebook requires the conda environment backtest. Please see the installation instructions for running the latest Docker image or alternative ways to set up your environment.

Load zipline extensions

Only need this in notebook to find bundle.

Logging Setup

Algo Params

Load Data

Quandl Wiki Bundel

ML Predictions

Define Custom Dataset

Define Pipeline Loaders

Pipeline Setup

Custom ML Factor

Create Pipeline

Get daily Pipeline results

Define Rebalancing Logic

Equal Weights

Markowitz Mean-Variance Optimization

Hierarchical Risk Parity

Record Additional Data Points

Define addtional variables to capture in the results DataFrame.

Initialize Algorithm with PF optimization algorithm

Execute run_algorithm once with each algorithm:

Select portfolio optimization algorithm

Here we set the algo we are going to use:

Schedule rebalancing using selected algo

Run trading algorithm for each PF optimization approach

Persist experiment results

Comparing results using pyfolio

Once you're run the three algorithms (or those you're interested in), let's compare the results.

Load benchmark

Cumulative Returns & Rolling Sharpe Ratios

Tear Sheets

Equal Weighted

HRP

Markowitz